package cn.sh.ideal.yedis.util;

import java.util.Collection;

public abstract class Assert {
	public static void isTrue(boolean expression, String message) {
		if (!expression) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isTrue(boolean expression) {
		isTrue(expression, "[Assertion failed] - this expression must be true");
	}

	public static void isNull(Object object, String message) {
		if (object != null) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isNull(Object object) {
		isNull(object, "[Assertion failed] - the object argument must be null");
	}

	public static void notNull(Object object, String message) {
		if (object == null) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void notNull(Object object) {
		notNull(object, "[Assertion failed] - this argument is required; it must not be null");
	}


	public static void notEmpty(String str, String message) {
		if (StringUtil.isEmpty(str)) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void notEmpty(String str) {
		notEmpty(str,
				"[Assertion failed] - this string must not be empty");
	}

	public static void notEmpty(Collection<?> collection, String message) {
		if (null == collection || collection.isEmpty()) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void notEmpty(Collection<?> collection) {
		notEmpty(collection,
				"[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
	}
	
	public static void notEmpty(Object[] array, String message) {
		if (array == null || array.length == 0) {
			throw new IllegalArgumentException(message);
		}
	}
	
	public static void hasLength(Object[] array, int length, String message) {
		if (array == null || array.length != length) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void notEmpty(Object[] array) {
		notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
	}
}
